<template>
  <view>
    <view v-if="itemList && itemList.length > 0">
      <view class="grid-body mt-30" v-for="(item, index) in itemList" :key="index">
        <view class="check grid-common">
          <view class="flex text bor-top justify-between">
            <view class="title flex">
              <image class="icon-style" src="/static/images/icon-stay.png" mode="aspectFill"></image>
              {{ item.overhaulCategoryLabel }}
            </view>
            <view>
              当前状态： <text class="text-grey">{{ item.taskStatusLabel }}</text></view
            >
          </view>
          <view class="flex text">
            任务名称：<text>{{ item.taskName }}</text>
          </view>
          <view class="flex text">
            编号：<text>{{ item.taskNumber }}</text>
          </view>
          <view class="flex text">
            设备分组：<text>{{ item.deviceGroupLabel }}</text>
          </view>
          <view class="flex text">
            设备类型：<text>{{ item.deviceTypeName }}</text>
          </view>
          <view class="flex text">
            设备名称：<text>{{ item.deviceName }}</text>
          </view>
          <!-- 			<view> 当前节点： <text class="text-grey">{{item.nodeName}}</text></view> -->
          <view class="flex text">
            所属作业项目：<text>{{ item.projectName }}</text>
          </view>
          <view class="footer-wrap">
            <view class="content-wrap"> </view>
            <view class="button-wrap">
              <button class="button" @click="goView(item)">查看</button>
              <button v-if="item.taskStatus === '1'" class="button button-orange" @click="remove(item)">删除</button>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import Empty from '@/components/cu-empty/index.vue'
import { getRepairTaskList, deleteTask } from '@/api/repair/repair.js'
export default {
  name: 'pointCheck',
  components: {
    Empty
  },
  data() {
    return {
      itemList: [],
      queryParams: {
        pageSize: 10,
        pageNum: 1
      },
      totol: 0
    }
  },
  onNavigationBarButtonTap(e) {
    uni.navigateTo({
      url: '/pages/work/intelligentPatrolInspection/maintenanceRequirement/report'
    })
  },
  onLoad() {
    this.getItemList()
  },
  onShow() {
    this.getItemList()
  },
  methods: {
    onPullDownRefresh() {
      this.queryParams.pageNum = 1
      this.getItemList()
    },
    onReachBottom() {
      const { pageNum, pageSize } = this.queryParams
      if (pageNum * pageSize < this.total) {
        this.queryParams.pageNum += 1
        this.getItemList(false)
      }
    },
    async getItemList(isRefresh = true) {
      const { total, rows } = await getRepairTaskList(this.queryParams).finally(() => uni.stopPullDownRefresh())
      if (isRefresh) {
        this.itemList = rows || []
      } else {
        this.itemList = [...this.itemList, ...rows]
      }
      this.total = total
    },
    // getItemList() {
    // 	queryList().then(res => {
    // 		this.itemList = res.rows
    // 	})
    // },
    goView(item) {
      uni.navigateTo({
        url: '/pages/work/intelligentPatrolInspection/maintenanceRequirement/info?id=' + item.taskId
      })
    },
    edit(item) {
      uni.navigateTo({
        url: '/pages/work/intelligentPatrolInspection/maintenanceRequirement/maintenanceEdit?id=' + item.taskId
      })
    },
    remove(item) {
      uni.showModal({
        title: '提示',
        content: '删除后， 该检修需求将不可找回， 请确定是否删除？ ',
        success: function (res) {
          if (res.confirm) {
            deleteTask(item.taskId).then(() => {
              uni.redirectTo({
                url: '/pages/work/intelligentPatrolInspection/maintenanceRequirement/index'
              })
              this.$modal.showToast('删除成功')
            })
          }
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.check {
  position: relative;

  .title {
    font-size: 34rpx;
    font-weight: 700;
  }

  .icon-style {
    width: 52rpx;
    height: 52rpx;
    margin-right: 20rpx;
  }

  .text {
    display: flex;
    color: #999;

    text {
      color: #333;
      display: inline-block;
    }
  }

  .bor-top {
    padding-top: 20rpx;
    border-top: 1px solid #d5d7e3;
  }
}
</style>
